//
//  PaidTableViewCell.m
//  HTP
//
//  Created by 王鑫 on 15/11/2.
//  Copyright © 2015年 nit. All rights reserved.
//

#import "PayTableViewCell.h"
#import "MyOrderViewModel.h"

@interface PayTableViewCell ()

@property (nonatomic, retain) UILabel *infoLabel;

@property (nonatomic, retain) UIImageView *icoImage;

@property (nonatomic, retain) UILabel *nameLabel;

@property (nonatomic, retain) UILabel *priceLabel;

@property (nonatomic, retain) UILabel *timeLabel;

@property (nonatomic, retain) UILabel *orderNum;

@property (nonatomic, retain) UILabel *moneyLabel;

@property (nonatomic, retain) UIImageView *payImage;

@property (nonatomic, retain) UIImageView *line1;

@property (nonatomic, retain) UIImageView *line2;

@property (nonatomic, retain) MyOrderModel *myOrder;

@end

@implementation PayTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self _initUI];
    }
    return self;
}

- (void)_initUI {
    _infoLabel = [[UILabel alloc] init];
    _infoLabel.font = [UIFont systemFontOfSize:19.0f];
    [self.contentView addSubview:_infoLabel];
    
    _icoImage = [[UIImageView alloc] init];
    [_icoImage setBackgroundColor:[UIColor blackColor]];
    [self.contentView addSubview:_icoImage];
    
    _nameLabel = [[UILabel alloc] init];
    _nameLabel.font = [UIFont systemFontOfSize:16.0f];
    [self.contentView addSubview:_nameLabel];
    
    _priceLabel = [[UILabel alloc] init];
    _priceLabel.font = [UIFont systemFontOfSize:16.0f];
    [self.contentView addSubview:_priceLabel];
    
    _timeLabel = [[UILabel alloc] init];
    _timeLabel.font = [UIFont systemFontOfSize:16.0f];
    [self.contentView addSubview:_timeLabel];
    
    _orderNum = [self getNormolLabel];
    _orderNum.font = [UIFont systemFontOfSize:12.0f];
    [_orderNum setTextColor:RGBCOLOR(100, 100, 100, 1)];
    [_orderNum setTextAlignment:_TEXT_ALIGN_LEFT];
    [self.contentView addSubview:_orderNum];
    
    _moneyLabel = [self getNormolLabel];
    [self.contentView addSubview:_moneyLabel];
    
    _payImage = [[UIImageView alloc] init];
    _payImage.image = [UIImage imageNamed:@"支付按钮"];
    _payImage.contentMode = UIViewContentModeScaleAspectFit;
    [self.contentView addSubview:_payImage];
    
    _line1 = [[UIImageView alloc] init];
    [_line1 setAlpha:0.6];
    [self.contentView addSubview:_line1];
    
    _line2 = [[UIImageView alloc] init];
    [_line2 setAlpha:0.6];
    [self.contentView addSubview:_line2];
}

-(void)layoutSubviews{
    [_icoImage setFrame:CGRectMake(5, 40, 105, 90)];
    
    [_infoLabel setFrame:CGRectMake(5, 5, 200, 20)];
    
    [_nameLabel setFrame:CGRectMake(115, 45, ScreenWidth - 120, 25)];
    
    [_priceLabel setFrame:CGRectMake(115, 74, ScreenWidth - 120, 25)];
    
    [_timeLabel setFrame:CGRectMake(115, 103, ScreenWidth - 120, 25)];
    
    CGSize orderSize = [_orderNum.text textSizeWithFont:_orderNum.font constrainedSize:CGSizeMake(ScreenWidth / 2.0, 25)];
    [_orderNum setFrame:CGRectMake(5, 160, orderSize.width, orderSize.height)];
    
    int flag = [_myOrder.ordStatus intValue];
    if (flag == 3 || flag == 2) {//订单完成
        [_moneyLabel setFrame:CGRectMake(ScreenWidth / 2.0, 155, ScreenWidth / 2.0 - 10, 20)];
        [_moneyLabel setTextAlignment:_TEXT_ALIGN_RIGHT];
        [_payImage removeFromSuperview];
    }else{
        if (!_payImage.superview) {
            [self.contentView addSubview:_payImage];
        }
        [_payImage setFrame:CGRectMake(ScreenWidth - 60, 150, 50, 25)];
        [_moneyLabel setFrame:CGRectMake(ScreenWidth / 2.0 , 155, ScreenWidth /2.0 - 60, 20)];
        [_moneyLabel setTextAlignment:_TEXT_ALIGN_CENTER];
    }
    
    
    [_line1 setFrame:CGRectMake(0, 30, ScreenWidth, 2)];
    
    [_line2 setFrame:CGRectMake(0, 140, ScreenWidth, 2)];
}
- (void)setCellData:(MyOrderModel *)cellData {
    
    _myOrder = cellData;
    
    _infoLabel.text  = _myOrder.courseName;
    _nameLabel.text  = [NSString stringWithFormat:@"姓名: %@",_myOrder.teacherName];
    _priceLabel.text = [NSString stringWithFormat:@"价格: ￥%@/h",_myOrder.ordSinglePrice];
    _timeLabel.text  = [NSString stringWithFormat:@"时间: %@",_myOrder.ordCreatTime];
    _orderNum.text   = [NSString stringWithFormat:@"订单号: %@",_myOrder.ordCode];
    
   
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"￥%.2lf",[_myOrder.ordValue floatValue]]];
    NSInteger length = [NSString stringWithFormat:@"￥%.2lf",[_myOrder.ordValue floatValue]].length;
    [str addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:NSMakeRange(0, 0)];
    [str addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:22] range:NSMakeRange(1, length - 3)];
    [str addAttribute:NSForegroundColorAttributeName value:RGBCOLOR(100, 100, 100, 1) range:NSMakeRange(0, 0)];
    [str addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:NSMakeRange(1, length - 1)];
    _moneyLabel.attributedText = str;
//    _icoImage.image  = [UIImage imageNamed:_myOrder.teacherPhotoPath];
    [_icoImage setNormalImageUrl:_myOrder.teacherPhotoPath anplaceholder:@"m_teacher_z"];
    
    _line1.image = [UIImage imageNamed:@"横线"];
    _line2.image = [UIImage imageNamed:@"横线"];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
